<template>
	<view class="content">
		<view class="hei20"></view>
		<view class="wid90 mar borRad20 bacFFF" style="height: 318rpx;padding: 30rpx 0;">
			<view class="wid90 mar dis disAl">
				<image :src="url+image" style="width: 127rpx;height: 127rpx;"></image>
				<view class="mar-left20">
					<view class="foSi40 fowe600">{{list.gasstation.name}}</view>
					<view class="mar-top20 foSi25" style="color: #3A3A3A;">{{list.gasstation.address}}</view>
				</view>
			</view>
			<view class="wid90 mar dis disAl" style="margin-top: 57rpx;">
				<view class="wid25 textCen" @click="tiaozhuan('/pages/shop/cashier',1)">
					<image src="../../static/shouyin.png" style="width: 70rpx;height: 72rpx;"></image>
					<view class="foSi25 mar-top10">门店收银</view>
				</view>
				<view class="wid25 textCen" @click="tiaozhuan('/pages/verification/verification?name='+list.gasstation.name,2)">
					<image src="../../static/hexiao.png" style="width: 70rpx;height: 72rpx;"></image>
					<view class="foSi25 mar-top10">门店核销</view>
				</view>
				<view class="wid25 textCen" @click="tiaozhuan('/pages/salesclerk/salesclerk',3)">
					<image src="../../static/dianyuan.png" style="width: 70rpx;height: 72rpx;"></image>
					<view class="foSi25 mar-top10">门店店员</view>
				</view>
				<view class="wid25 textCen" @click="tiaozhuan('/pages/member/member',4)">
					<image src="../../static/hexiaoyuan.png" style="width: 70rpx;height: 72rpx;"></image>
					<view class="foSi25 mar-top10">会员管理</view>
				</view>
			</view>
		</view>
		<view class="wid90 mar borRad20 bacFFF mar-top30" style="padding: 30rpx 0;">
			<view class="wid90 mar">
				<view class="dis disAl disJuB">
					<view class="foSi35 fowe600">交易数据</view>
					<view class="foSi20" style="color: #878787;">数据统计截至{{date}}</view>
				</view>
				<view class="mar-top40" style="background: #F8F9FD;padding: 20rpx 0;">
					<view class="wid90 mar">
						<view>
							<view class="foSi22" style="color: #ACACAD;">今日营业额（元）</view>
							<view class="fowe600" style="vertical-align: bottom;">
								<span class="foSi30">￥</span>
								<span class="foSi50">{{list.today}}</span>
							</view>
						</view>
						<view class="mar-top30">
							<view class="mar-top30">
								<view class="foSi22" style="color: #ACACAD;">昨日营业额（元）</view>
								<view class="fowe600" style="vertical-align: bottom;">
									<span class="foSi30">￥</span>
									<span class="foSi40">{{list.yesterday}}</span>
								</view>
							</view>
							<view class="mar-top30">
								<view class="foSi22" style="color: #ACACAD;">本周营业额（元）</view>
								<view class="fowe600" style="vertical-align: bottom;">
									<span class="foSi30">￥</span>
									<span class="foSi40">{{list.week}}</span>
								</view>
							</view>
							<view class="mar-top30">
								<view class="foSi22" style="color: #ACACAD;">本月营业额（元）</view>
								<view class="fowe600" style="vertical-align: bottom;">
									<span class="foSi30">￥</span>
									<span class="foSi40">{{list.month}}</span>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="poFix wid100 bacFFF" style="bottom: 0;">
			<view class="wid90 mar dis disAl" style="height: 125rpx;">
				<view class="textCen" style="width: 40%;">
					<image src="../../static/tabbar/workbench-on.png" style="width: 40rpx;height: 40rpx;"></image>
					<view class="mar-top10 foSi25" style="color: #035DFF;">工作台</view>
				</view>
				<view class="textCen" style="width: 20%;" @click="scan">
					<image src="../../static/tabbar/zu.png" style="width: 135rpx;height: 135rpx;margin-top: -50rpx;"></image>
				</view>
				<view class="textCen" style="width: 40%;" @click="tiaozhuan1('/pages/shop/wode')">
					<image src="../../static/tabbar/install.png" style="width: 40rpx;height: 40rpx;"></image>
					<view class="mar-top10 foSi25">设置</view>
				</view>
			</view>
			<view v-if="bottomHight != 0" :style="'height: '+(bottomHight - 20)+'px;'"></view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				url: this.global.url,
				bottomHight: 0,
				image: '/addon/qianyu_petrol/wxapp/image/tu2.png',
				list: '',
				date: '', //现在时间
				timer: null,
				code: ''
			}
		},
		onLoad() {
			var that = this
			let app = uni.getSystemInfoSync();
			that.bottomHight = app.safeAreaInsets.bottom //屏幕底部安全距离
			that.date = that.dateFormat(new Date())
			that.timer = setInterval(function() {
				const now = new Date();
				if (now.getSeconds() == 1) {
					that.date = that.dateFormat(now)
					that.$forceUpdate()
					console.log(that.date)
				}
			}, 1000);
		},
		onShow() {
			this.getList()
		},
		onUnload() {
			console.log('pand1')
			if(this.timer) {
				clearTimeout(this.timer);  
				this.timer = null;  
			}  
		},
		methods: {
			dateFormat(time) {
				let date = new Date(time);
				let year = date.getFullYear();
				// 在日期格式中，月份是从0开始的，因此要加0，使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
				let month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
				let day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
				let hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
				let minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
				let seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
				// 拼接
				return year + "年" + month + "月" + day + "日 " + hours + ":" + minutes;
				// return year + "-" + month + "-" + day;
			},
			getList() {
				var that = this;
				var yuan_userinfo = uni.getStorageSync('yuan_userinfo')
				uni.request({
					url: that.global.url + '/api/qianyu_petrol/gasstation_clerk_staging',
					method: "POST",
					header: {
						'site-id': that.global.site_id,//自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {
						gas_station_id: yuan_userinfo.gas_station_id
					},
					success(res) {
						let result = res.data
						console.log(result)
						if (result.code == 1) {
							that.list = result.data
							var img = result.data.gasstation.img.split(',')
							that.image = img[0]
						}
					}
				})
			},
			scan: function(e){
				var that = this;
				uni.scanCode({
				    onlyFromCamera: true,
				    success: function (res) {
				        //console.log('条码内容：' + res.result);
						var strs= new Array(); //定义一数组 
						strs=res.result.split("_"); //字符分割
						that.code = strs[0];
						uni.showModal({
						    title: '温馨提示',
						    content: '确认要核销吗?',
						    success: function (res) {
						        if (res.confirm) {
									that.getCheck()
						        } else if (res.cancel) {
						            uni.showToast({
						            	title:'取消核销',
						            	icon:'none'
						            })
						        }
						    }
						});
				    }
				})
			},
			
			getCheck() {
				var that = this;
				var yuan_userinfo = uni.getStorageSync('yuan_userinfo')
				uni.request({
					url: that.global.url + '/api/qianyu_petrol/gasstation_integralorder_check',
					method: "POST",
					header: {
						'site-id': that.global.site_id,//自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {
						'gas_station_id': yuan_userinfo.gas_station_id,
						'clerk_id': yuan_userinfo.id,
						'code': that.code
					},
					success(res) {
						let result = res.data
						console.log(result)
						if (result.code == 1) {
							uni.showToast({
								title: '核销成功',
								icon: 'none',
								duration: 1000
							});
						}else{
							uni.showToast({
								title: result.msg,
								icon: 'none',
								duration: 1000
							});
						}
					}
				})
			},
			tiaozhuan(url,i){
				var yuan_userinfo = uni.getStorageSync('yuan_userinfo')
				if(yuan_userinfo.counterpoise.indexOf(i) != -1){
					uni.navigateTo({
						url: url
					})
				}else{
					uni.showToast({title: '暂无权限',icon: 'none',duration: 1000});
				}
			},
			tiaozhuan1(url){
				uni.redirectTo({
					url: url
				})
			}
		}
	}
</script>

<style>
	.content {
		background: #F8F9FD;
		min-height: 100vh;
	}

</style>
